<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Admin Template">
    <meta name="keywords" content="admin dashboard, admin, flat, flat ui, ui kit, app, web app, responsive">
    <link rel="shortcut icon" type="image/png" href="/blogobj/images/home/code1.jpg">
    <title>登录|呵哈糊涂</title>

    <!-- Base Styles -->
    <link href="/basetemplate/css/style.css" rel="stylesheet">
    <link href="/basetemplate/css/style-responsive.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="/basetemplate/js/html5shiv.min.js"></script>
    <script src="/basetemplate/js/respond.min.js"></script>
    <![endif]-->


</head>

<body class="login-body">

<div class="login-logo">
    <img src="/blogobj/images/home/logo.png" alt=""/>
</div>

<h2 class="form-heading">暂时仅提供修改密码功能@_@</h2>
<div class="container log-row">
    <form class="form-signin" action="" method="post" id="subuser">
        {% with message = get_flashed_messages() %}
            {% if message %}
                {% for msg in message %}
                    <div class="alert alert-success">
                        <a href="#" class="close" data-dismiss="alert">&times;</a>
                        {{ msg }}
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}
        <div class="login-wrap">
            <input type="text" class="form-control" placeholder="旧密码" name="password" autofocus>
            <input type="password" class="form-control" placeholder="新密码" id="newpassword" name="newpassword">
            <input type="password" class="form-control" placeholder="重复新密码" id="repassword" name="repassword">
            <button class="btn btn-lg btn-success btn-block" type="submit">确认修改</button>

        </div>

        <!-- Modal -->
        <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="reenter"
             class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">警告</h4>
                    </div>
                    <div class="modal-body">
                        <p>您输入的初始密码有误，请重新输入</p>

                    </div>
                    <div class="modal-footer">

                        <button class="btn btn-success" type="button" data-dismiss="modal">确认</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- modal -->

    </form>
</div>

<!--jquery-1.10.2.min-->
<script src="/basetemplate/js/jquery-1.11.1.min.js"></script>
<script src="//cdn.bootcss.com/jquery-validate/1.15.1/jquery.validate.min.js"></script>
<script src="//cdn.bootcss.com/jquery-validate/1.15.1/additional-methods.min.js"></script>
<!--Bootstrap Js-->
<script src="/basetemplate/js/bootstrap.min.js"></script>
<script src="/basetemplate/js/jrespond..min.js"></script>

</body>
</html>
<script>
    $(document).ready(function () {
        $("#subuser").validate({
            rules:{
                newpassword:{required: true, minlength:6, maxlength:12},
                repassword:{required: true, equalTo: '#newpassword'}

            },
            messages:{
                newpassword:{required: "密码不能为空", minlength: "密码最小为6个字符", maxlength: "密码最大为12个字符"},
                repassword:{required: "不能为空", equalTo: "两次输入密码不一致"}
            },
            submitHandler: function (form) {
                $.ajax({
                    method: 'POST',
                    url: '{{ url_for('admin.edit_user') }}',
                    data: $("form").serialize(),
                    datatype: 'json',
                    success: function (rep) {
                        if(rep.num ==1){
                            window.location.href='{{ url_for('admin.login') }}'
                        }
                        if(rep.num ==2){
                            $("#reenter").modal()
                        }

                    }
                });
            }
        });
    });
</script>